<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面单列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__CSS__/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>面单列表</h5>
        </div>
        <div class="ibox-content">
            <div class="form-group clearfix col-sm-1">
                <a href="{:url('pack/scan',array('type'=>'sign'))}" target="_black">
                    <button class="btn btn-outline btn-primary" type="button">扫码签收</button>
                </a>
            </div>

            <div class="form-group clearfix col-sm-1">  
                <a href="{:url('pack/scanSend',array('type'=>'scanSend'))}" target="_black">
                    <button class="btn btn-outline btn-success" type="button">扫码发货</button>
                </a>
            </div>

            <div class="form-group clearfix col-sm-1">  
                <a href="JavaScript:;" onclick="batchDelivery()">
                    <button class="btn btn-outline btn-success" type="button"><i class="fa fa-truck"></i> 批量发货</button>
                </a>
            </div>
            <!--搜索框开始-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <select class="form-control" name="platform_code" id="platform_code" onchange="updateDate()">
                            <option value="0">选择平台</option>
                            {foreach name="platform" item="item" key="key"}
                                <option value="{$key}" {if condition="$platform eq $key"}selected{/if}>{$item.name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="pay_status" id="pay_status" onchange="updateDate()">
                            <option value="1" {if condition="$pay_status eq 1"}selected{/if}>已支付</option>
                            <option value="0" {if condition="$pay_status eq 0"}selected{/if}>未支付</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="pack_status" id="pack_status" onchange="updateDate()">
                            <option value="0">面单状态</option>
                            <option value="1" {if condition="$pack_status eq 1"}selected{/if}>已确认</option>
                            <option value="2" {if condition="$pack_status eq 2"}selected{/if}>已签收</option>
                            <option value="3" {if condition="$pack_status eq 3"}selected{/if}>已发货</option>
                        </select>
                    </div>
                   
                    <div class="form-group">
                        <input type="text" class="form-control" id="pack_number" name="pack_number" placeholder="面单号">
                    </div>

                    <div class="form-group">
                        <input type="text" class="form-control" id="express_number" name="express_number" placeholder="物流单号">
                    </div>
                    
                    <div class="form-group">
                        <input type="hidden"  id="pack_id" name="pack_id" value="{$pack_id}">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th data-field="pack_id">面单ID</th>
                        <th data-field="platform_code">平台</th>
                        <th data-field="pack_number">面单号</th>
                        <th data-field="express_str">相关物流</th>
                        <th data-field="pack_note" data-width="200px">客户备注</th>
                        <th data-field="create_time">创建时间</th>
                        <th data-field="update_time">更新时间</th>
                        <th data-field="is_print">面单状态</th>
                        <th data-field="pack_status">订单状态</th>
                        <th data-field="pay_status">支付状态</th>
                        <th data-field="operate">操作</th>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="__JS__/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__JS__/plugins/layer/laydate/laydate.js"></script>
<script src="__JS__/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__JS__/plugins/layer/layer.min.js"></script>
<script type="text/javascript">
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "./index", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    pack_number:$('#pack_number').val(),
                    pay_status:$('#pay_status').val(),
                    platform_code:$('#platform_code').val(),
                    pack_status:$('#pack_status').val(),
                    pack_id:$('#pack_id').val(),
                    express_number:$('#express_number').val(),
                };
                return param;
            },
            columns: [{
                    checkbox: true,  
                    visible: true                  //是否显示复选框  
            }], 
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);
    });

    function updateDate() {
        $('#pack_id').val('');
        $('#pay_id').val('');
        initTable();
    }

    function checkPrint(id,file){
        window.open(file);
        layer.confirm('已打印面单?', {icon: 3, title:'提示'}, function(index){

            $.post("{:url('pack/setPackSatus')}", {id: id}, function(data, textStatus, xhr) {
                if (data.code==1) {
                    layer.alert(data.msg, {title: '友情提示', icon: 1},function(index){
                      initTable();
                      layer.close(index);
                    });      
                }else{
                    layer.alert(data.msg, {title: '友情提示', icon: 2});
                }
            },'json');

            layer.close(index);
        })
    }
    //删除
    function del(id){
        layer.confirm('面单以及对应的商品信息将被删除，确认操作吗?', {icon: 3, title:'提示'}, function(index){
            $.post("{:url('pack/delPack')}", {id: id}, function(data, textStatus, xhr) {
                if (data.code==1) {
                    layer.alert(data.msg, {title: '友情提示', icon: 1},function(index){
                      initTable();
                      layer.close(index);
                    });      
                }else{
                    layer.alert(data.msg, {title: '友情提示', icon: 2});
                }
            },'json');
            layer.close(index);
        })
    }
    //签收
    function setSign(id){
        layer.confirm('该面单对应的所有商品将被标记为已确认，确认已签收该面单吗?', {icon: 3, title:'提示'}, function(index){
            $.post("{:url('pack/setSign')}", {id: id}, function(data, textStatus, xhr) {
                if (data.code==1) {
                    layer.alert(data.msg, {title: '友情提示', icon: 1},function(index){
                      initTable();
                      layer.close(index);
                    });      
                }else{
                    layer.alert(data.msg, {title: '友情提示', icon: 2});
                }
            },'json');
            layer.close(index);
        })
    }
    //发货
    function setShipping(id){
        layer.confirm('确认该面单已发货吗?', {icon: 3, title:'提示'}, function(index){
            $.post("{:url('pack/setShipping')}", {id: id}, function(data, textStatus, xhr) {
                if (data.code==1) {
                    layer.alert(data.msg, {title: '友情提示', icon: 1},function(index){
                      initTable();
                      layer.close(index);
                    });      
                }else{
                    layer.alert(data.msg, {title: '友情提示', icon: 2});
                }
            },'json');
            layer.close(index);
        })
    }
    function batchDelivery() {
        var a= $("#cusTable").bootstrapTable('getRowByUniqueId');     
        console.log(a);                  
        // if(data.length<=0){                           
        //     layer.msg('请至少选择一行数据');                 
        // }else{                          
        // var b=JSON.stringify(a); 
        // $.post('{:url("Pack/setShipping")}', b, function(data, textStatus, xhr) {
        //     /*optional stuff to do after success */
        // });                              
    // }   





    	// layer.msg('开发中···敬请期待');
    	// setTimeout(function() {
    	// 	window.location.reload();
    	// }, 2000);
    	
    }
</script>
</body>
</html>
